<?php 
namespace App;

use Illuminate\Database\Eloquent\Model;
use DB;

class Index extends Model
{

//查询所有分类
public function select(){
	  
	   	   $data=DB::table('cate')->select('cate_id','cate_name','parent_id')->where('cate_status',0 )->get();
			// dd($data);
			return $data;
	 
	}

	//无限极分类
	function getChilds($data,$pid=0){
		$arr=array();
		foreach($data as $key=>$val){
			if($val->parent_id==$pid){
				$child=$this->getChilds($data,$val->cate_id);
				if($child){
					$val->child=$child;
				}
				$arr[]=$val;
			}
		}
		return $arr;
	}
}

 ?>

